package myadmin.jtthink.com.MyServices;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import myadmin.jtthink.com.Mapper.DeptMapper;
import myadmin.jtthink.com.Models.DeptModel;

import myadmin.jtthink.com.MyAnnotations.GET;
import myadmin.jtthink.com.MyAnnotations.MethodName;
import myadmin.jtthink.com.MyAnnotations.POST;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptService extends ServiceImpl<DeptMapper, DeptModel>
        implements IDept  {


    @GET
    @MethodName("list")
    public List<DeptModel> getAllDept(){
        System.out.println(SecurityContextHolder.getContext().
                getAuthentication().getPrincipal());
        System.out.println(SecurityContextHolder.getContext().
                getAuthentication().getAuthorities());

        QueryWrapper<DeptModel> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return this.list(queryWrapper);
    }

    @POST
    @MethodName("post")
//    @PreAuthorize("hasRole('SYS') or hasAuthority('update')")
    public String postdept(){
        System.out.println(SecurityContextHolder.getContext().
                getAuthentication().getPrincipal());
        System.out.println(SecurityContextHolder.getContext().
                getAuthentication().getAuthorities());
        return "修改部门成功";
    }

    @GET
    @MethodName("test")
    public String test(){
        return "test";
    }
}
